﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using PlayerSDK;
using IPlayer;

namespace TestPlayerSDKHC
{
    public partial class Form1 : Form
    {
        PlayerSDKHC player = new PlayerSDKHC();
        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }


        private void bOpen1_Click(object sender, EventArgs e)
        {
            if (this.player.OpenState == OpenStateEnum.FilePlay) this.player.Close();
            this.tPosition.Stop();

            this.player.Open(@"V:\ch01_20090618171950.mp4",this.Handle);
            TimeSpan TS = new TimeSpan(this.player.GetFileTime() * 10000000);
            this.lFileTime.Text = "总时长:" + TS.ToString();
            this.lTotalFrames.Text = "总帧数:" + this.player.GetTotalFrames();
            this.lFrameRate.Text = "帧率:" + this.player.GetFrameRate();

            this.Invalidate();
        }

        private void bOpen2_Click(object sender, EventArgs e)
        {
            if (this.player.OpenState == OpenStateEnum.FilePlay) this.player.Close();
            this.tPosition.Stop();

            this.player.Open(@"V:\test.mp4", this.Handle);
            TimeSpan TS = new TimeSpan(this.player.GetFileTime() * 10000000);
            this.lFileTime.Text = "总时长:" + TS.ToString();
            this.lTotalFrames.Text = "总帧数:" + this.player.GetTotalFrames();
            this.lFrameRate.Text = "帧率:" + this.player.GetFrameRate();

            this.Invalidate();
        }


        private void bStop_Click(object sender, EventArgs e)
        {
            this.tPosition.Stop();
            this.player.Stop();
        }

        private void bClose_Click(object sender, EventArgs e)
        {
            this.tPosition.Stop();
            this.player.Close();
        }

        private void bPlay_Click(object sender, EventArgs e)
        {
            this.player.Play();
            tPosition.Start();
        }

        private void bPause_Click(object sender, EventArgs e)
        {
            this.player.Pause();
        }

        private void bContinue_Click(object sender, EventArgs e)
        {
            this.player.Continue();
        }

        private void bFast_Click(object sender, EventArgs e)
        {
            this.player.Fast();
        }

        private void bSlow_Click(object sender, EventArgs e)
        {
            this.player.Slow();
        }

        private void bOneByOne_Click(object sender, EventArgs e)
        {
            this.player.OneByOne();
        }

        private void tPosition_Tick(object sender, EventArgs e)
        {
            float position = this.player.GetPlayPos();
            this.hSBPosition.Value = Convert.ToInt32(position * 1000);
            TimeSpan TS = new TimeSpan( this.player.GetPlayedTime() * 10000000);
            this.lPlayedTime.Text = "播放时间:" + TS.ToString();
        }

        private void nUDPosition_ValueChanged(object sender, EventArgs e)
        {
            tPosition.Stop();
            float position = (float)(this.nUDPosition.Value / 100);
            this.player.SetPlayPos(position);
            tPosition.Start();
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x1111)
            {
                this.player.Stop();
                MessageBox.Show("播放完毕");
            }
            base.WndProc(ref m);
        }


    }
}
